<?php

namespace app\http\middleware;

use app\facade\Token;
use think\Db;
use app\facade\Redis;

class Auth
{
    use \traits\controller\Jump;

    public function handle($request, \Closure $next)
    {
        $url = '/' . $request->controller() . '/' . $request->action();
        $url = strtolower($url);
        $verify = config('auth.api');
        // if (!in_array($url, $verify) && !$request->header('token') && $request->controller() != 'Rider') {
        //     $this->result(null, 999, '请授权登陆账号');
        // }

        $ip = $request->ip();
        $code = $ip;
        if ($request->isPost() && $url != '/other/list') {
            $unique = date('YmdHi') . '_' . $url . '_' . $code;
            $frtimes = Redis::get($unique);
            if ($frtimes) {
                $this->result(null, 404, '操作频繁，请重试');
            } else {
                Redis::setex($unique, 1, 1);
            }
        }
        return $next($request);
    }
}
